<?php
// +---------------------------------------------------------------------------+
// | This file is part of the KnowledgebasePublisher package                   |
// | KnowledgebasePublisher - web based knowledgebase publisher tool           |
// |                                                                           |
// | Author:  Evgeny Leontev <eleontev@gmail.com>                              |
// | Copyright (c) 2005 Evgeny Leontev                                         |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

require_once $controller->working_dir . 'inc/KBComment.php';
require_once $controller->working_dir . 'inc/KBCommentModel.php';


// initialize objects
$rq =& new RequestData($_GET);
$rp =& new RequestData($_POST);

$obj = new KBComment;

$manager =& $obj->setManager(new KBCommentModel());
$manager->checkPriv($priv, $controller->action, @$rq->id);



switch ($controller->action) {
case 'delete': // ------------------------------
	
	$manager->delete($rq->id);
	$controller->go();

	break;
	

case 'status': // ------------------------------
	
	$manager->status($rq->status, $rq->id);
	$controller->go();

	break;
	
	
case 'update': // ------------------------------
case 'insert': // ------------------------------
	
	if(isset($rp->submit)) {
		
		$is_error =& $obj->validate($rp->vars);
		
		if($is_error) {
			$rp->stripVars(true);
			$obj->set($rp->vars);
		
		} else {
			$rp->stripVars();
			$obj->set($rp->vars);
		
			$manager->save($obj);
			
			$controller->go();
		}
		
		
	} elseif($controller->action == 'update') {
	
		$data = &$manager->getById($rq->id);
		$rp->stripVarsValues($data);
		$obj->set($data);	
	}
	
	
	$view = &$controller->getView($obj, $manager, 'KBCommentView_form');

	break;


default: // ------------------------------------
	
	$view = &$controller->getView($obj, $manager, 'KBCommentView_list');
}
?>